<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>


<% 
	long asd = 0;
	String debug = "bad";
	String code = request.getParameter("code");
	String email = request.getParameter("email");
	String good_email = request.getParameter("email");
	long current = new Date().getTime();
	
	if(code != null && email != null){
		asd = (current - Long.parseLong(code));
		if((current - Long.parseLong(code)) < 600000){
			debug = "good";
		}else{
			good_email = null;
		}
	}
%>

			<sql:transaction dataSource="jdbc/lut2">
    			<sql:update var="count">
					INSERT INTO users (uname, pw, email) SELECT uname, pw, email FROM temp_users WHERE email=?;
					<sql:param><%= good_email %></sql:param>
    			</sql:update>
			</sql:transaction>
			
			<sql:transaction dataSource="jdbc/lut2">
    			<sql:update var="count">
					DELETE FROM temp_users WHERE email=?;
					<sql:param><%= email %></sql:param>
    			</sql:update>
			</sql:transaction>
    
<c:set var="userDetails" value="${users.rows[0]}"/>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="lutstyle.css">
        <title>LUT Login</title>
    </head>
    <body>
        <h1>Please Login</h1>
              <table border="0">
            <thead>
                <tr>
                    <th>You must login first before submitting any reviews</th>
                </tr>
            </thead>
            <tbody>
            	<!-- username and password here -->
                <tr>
                    <td>

                    	<form action="login_check.jsp">
							Username: <input id="username" type="text" name="username" placeholder="..." onfocus="if(this.placeholder == '...') { this.placeholder=''}" onblur="if(this.placeholder == '') { this.placeholder='...'}"><br>
							Password:&nbsp; <input id="password" type="password" name="password"><br>
							                    <span style="float:left;">
							<input type="submit" value="Log in">  							</span></form>
<span style="float:left;">
							<form action="register.jsp"><input type="submit" value="Register"></form>
							</span>
							<span style="float:left;"> 
							<form action="forgot.jsp"><input type="submit" value="Forgot password?"></form>
							</span> 
                    </td>
                </tr>
            </tbody>
        </table>

    </body>
</html>
